/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.comeval.persistencia;

import com.comeval.modelo.Rol;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author LUISA
 */
@Stateless
public class RolDAO implements IRolDAO {

    @PersistenceContext
    private EntityManager entityManager;

    @Override
    public List<Rol> consultar() {
        try {
            String jpql = "select r from Rol r";
            Query query = entityManager.createQuery(jpql);
            return query.getResultList();
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public Rol consultarPorRol(Integer rol) {
        try{
            return entityManager.find(Rol.class, rol);
        }catch(RuntimeException e){
            throw e;
        }
    }

}
